package by.msokoloff.javaweb2015.services.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.metamodel.SingularAttribute;

import org.springframework.stereotype.Service;

import by.msokoloff.javaweb2015.dataaccess.AdmUserDao;
import by.msokoloff.javaweb2015.datamodel.AdmUser;
import by.msokoloff.javaweb2015.datamodel.enums.AdmUserStatus;
import by.msokoloff.javaweb2015.services.AdmUserService;

@Service
public class AdmUserServiceImpl implements AdmUserService {

	@Inject
	private AdmUserDao dao;

	@Override
	public AdmUser get(Integer id) {
		return dao.getById(id);
	}
	
	@Override
	public List<AdmUser> getAll() {
		return dao.getAll();
	}
	
	@Override
	public List<AdmUser> getByStatus(AdmUserStatus status) {
		return dao.getByStatus(status);
	}

	@Override
	public List<AdmUser> getByField(SingularAttribute<AdmUser, ?> attr, Object val) {
		return dao.getByField(attr, val);
	}
	
	@Override
	public void createOrUpdate(AdmUser admUser) {
		if (admUser.getId() == null) {
			dao.create(admUser);
		} else {
			dao.update(admUser);
		}
	}

	@Override
	public void delete(AdmUser admUser) {
		dao.delete(admUser.getId());
	}
	
	@Override
	public void delete(List<Integer> ids) {
		dao.delete(ids);
	}

	@Override
	public void deleteAll() {
		dao.deleteAll();
	}

	@Override
	public Long getCount() {
		return dao.getCount();
	}
	
	@Override
	public List<AdmUser> getAll(SingularAttribute<AdmUser, ?> attr, boolean ascending, int startRecord, int pageSize) {
		return dao.getAll(attr, ascending, startRecord, pageSize);
	}

}
